<template>
	<a-modal v-bind="options">
		<a-textarea v-model:value="params.failureReason" placeholder="请输入拒绝原因" :maxlength="100" />
	</a-modal>
</template>
<script setup lang="ts">
	import {reactive, ref, watch, toRef} from 'vue'
	import {Modal, message} from 'ant-design-vue'
	import {approvalHandle} from '@/api/invoicing-history'
	import {useStore} from '@/store/index'
	const hasPermissions = useStore().hasPermissions

	const props = defineProps<{
		id?: string
		visible: boolean
	}>()
	const emits = defineEmits(['update:visible','success','close'])

	const options = reactive({
		width: 450,
		centered: true,
		title: '拒绝',
		maskClosable: false,
		destroyOnClose: true,
		visible: toRef(props, 'visible'),
		onOk(){
			setApprovalHandle()
		},
		onCancel() {
			close()
		}
	})
	const visibles = reactive({
		applyInvoice: false
	})

	watch(
		() => props.visible,
		newVal => {
			if (newVal) {
			}
		}
	)
	const params = reactive({
		failureReason: null,
		approvalStatus: 12,
		orgItemId: props.id
	})

	// 关闭
	const close = () => {
		emits('update:visible', false)
		setTimeout(() => emits('close'), 100)
	}

	const setApprovalHandle = () => {
		if(!params.failureReason){
			return message.error('请输入拒绝原因')
		}
		params.orgItemId =  props.id
		approvalHandle(params).then(({data}) => {
			message.success('操作成功')
			emits('success')
			close()
		})
	}
</script>
<style lang="less"></style>
